from common.mysql.MySQLhelper import get_sql_helper

sqlhelper = get_sql_helper()

# 获取到用户标签
def get_friend_tag(old_user_id):
    return sqlhelper.fetch_all("select id, tag_id, friend_id, user_id from shequn_friend_tag where user_id = %s",
                                      (old_user_id))

def update_friend_tag(today, new_friend_id, user_id, old_friend_id):
    sqlhelper.update(
        "UPDATE shequn_friend_tag SET update_by = %s, update_time = %s, friend_id = %s, user_id = %s  WHERE friend_id = %s; ",
        ("admin", today, new_friend_id, user_id, old_friend_id))

def delete_friend_tag(old_friend_id):
    sqlhelper.delete("DELETE from shequn_friend_tag where friend_id = %s", (old_friend_id))

def insert_friend_tag_by_tag_id(id01, today, user_id, friend_id, tag_id):
    sqlhelper.insert_one(
        "INSERT INTO shequn_friend_tag (id, create_by, create_time, update_by, update_time, tag_id, user_id, friend_id) VALUES(%s, %s, %s, %s, %s, %s, %s, %s); ",
        (
            id01, 'admin', today, 'admin', today, tag_id, user_id, friend_id))

def insert_friend_tag_list(insert_wechat_data):
    sql = 'INSERT INTO shequn_friend_tag (id, create_by, create_time, update_by, update_time, tag_id, user_id, friend_id) VALUES(%s, %s, %s, %s, %s, %s, %s, %s);'
    sqlhelper.insert_list(sql, insert_wechat_data)

def delete_by_user_id(user_id):
    sqlhelper.delete("DELETE from shequn_friend_tag where user_id = %s", (user_id))